package com.workManager.base;

import com.workManager.service.RoleServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Thinkpad on 2017/3/8 0008.
 */

public class MethodFilter implements Filter {

    ApplicationContext ac = new ClassPathXmlApplicationContext("/config/spring/spring-mvc.xml");
    RoleServiceImpl  roleService = (RoleServiceImpl) ac.getBean("roleService");



    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("过滤器初始化----------------------------------------------------------");
         roleService.initRoleFunctionMap();
        System.out.println("过滤器初始化--------------");
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) servletRequest;
        String url = req.getRequestURI();
        String role = "1";
        boolean flag = roleService.checkRoleFunction(role,url);
        System.out.println("flag----:"+flag);
    }

    public void destroy() {

    }
}
